package edu.iss.javaproject.service;

import java.util.List;





import org.springframework.transaction.annotation.Transactional;

import edu.iss.javaproject.model.LeaveRecord;
import edu.iss.javaproject.model.PublicHolidays;
import edu.iss.javaproject.model.Users;
import edu.iss.javaproject.dao.LeaveDAO;
import edu.iss.javaproject.dao.PublicHolidayDAO;
import edu.iss.javaproject.dao.UserDAO;
import edu.iss.javaproject.exception.LeaveNotFoundException;
import edu.iss.javaproject.exception.UserNotFoundException;


public class LAPServiceImpl implements LAPService {

	
	private LeaveDAO leaveRecordDAO;
	private PublicHolidayDAO publicHolidayDAO;
	private UserDAO userDAO;
	
	public void setLeaveRecordDAO(LeaveDAO leaveRecordDAO) {
		this.leaveRecordDAO = leaveRecordDAO;
	}

	public void setPublicHolidayDAO(PublicHolidayDAO publicHolidayDAO) {
		this.publicHolidayDAO = publicHolidayDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	
	@Override
	public void save(Users user) {
		userDAO.save(user);
		
	}

	@Override
	public void save(LeaveRecord leaveRecord) {
		leaveRecordDAO.save(leaveRecord);
		
	}

	@Override
	public void save(PublicHolidays publicHolidays) {
		publicHolidayDAO.save(publicHolidays);
		
	}

	@Override
	public void update(Users user) {
		userDAO.update(user);
		
	}

	@Override
	public void update(LeaveRecord leaveRecord) throws LeaveNotFoundException {
		leaveRecordDAO.update(leaveRecord);
		
	}

	@Override
	public void update(PublicHolidays publicHolidays) {
		publicHolidayDAO.update(publicHolidays);
		
	}

	@Override
	public Users findByID(int id) throws UserNotFoundException {
		return userDAO.findByID(id);
	}

	@Override
	public LeaveRecord findByrefNO(int refNO) throws LeaveNotFoundException{
		return leaveRecordDAO.findByRefNo(refNO);
	}

	@Override
	public List<Users> findAllUsers() {
		return userDAO.findAll();
	}

	@Override
	public List<LeaveRecord> findAllLeaveRecords() { 
		return leaveRecordDAO.findAll();
	}

	@Override
	public List<PublicHolidays> findAllPublicHoliday() {
		return publicHolidayDAO.findAll();
	}

	@Override
	public void deleteUser(Users users) throws UserNotFoundException {
		userDAO.delete(users);
		
	}

	@Override
	public void deleteLeave(LeaveRecord leaveRecord) throws LeaveNotFoundException {
		leaveRecordDAO.delete(leaveRecord);
	}

	@Override
	public void deletePublicHoliday(PublicHolidays publicHolidays) {
		publicHolidayDAO.delete(publicHolidays);
		
	}

	@Override
	public List<LeaveRecord> findByUserID(int id) throws LeaveNotFoundException {
		
		return leaveRecordDAO.findByUserID(id);
	}

	@Override
	public int updateLeave(LeaveRecord record) {
		// TODO Auto-generated method stub
		
		int result=0;
		if(record.getLeaveStatus().equals("approved"))
			{
			System.out.println("approved");
			leaveRecordDAO.updateForApprove(record.getRefNo(), record.getComment(),record.getApprovedBy());
			}
		else 
			{
			System.out.println("approved");
			
			leaveRecordDAO.updateForReject(record.getRefNo(), record.getComment(),record.getApprovedBy());
			}
		return result;
		
	}

	@Override
	public List<LeaveRecord> findAllLeaveRecordsByManagerID(int managerid) {
		// TODO Auto-generated method stub
		return leaveRecordDAO.findAllLeaveRecordsByManagerID(managerid);
	}

	


	
}
